package com.baitiaojun.moments.service.impl;

import com.baitiaojun.api.domain.moments.UserMomentsStatus;
import com.baitiaojun.api.exception.ConditionException;
import com.baitiaojun.moments.mapper.UserMomentsStatusMapper;
import com.baitiaojun.moments.service.MomentsStatusService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @类名 MomentsStatusServiceImpl
 * @作者 白条君
 * @创建日期 2023/1/30 19:14
 * @版本 1.0
 */
@Service
public class MomentsStatusServiceImpl implements MomentsStatusService {

    @Resource
    private UserMomentsStatusMapper momentsStatusMapper;

    @Override
    public void editMomentsStatus(UserMomentsStatus momentsStatus) throws ConditionException {
        int res = momentsStatusMapper.updateByPrimaryKeySelective(momentsStatus);
        if (res == 0) {
            throw new ConditionException("更新动态状态信息失败");
        }
    }

    @Override
    public UserMomentsStatus getMomentsStatusByContentId(Long contentId) {
        return momentsStatusMapper.selectMomentsStatusByContentId(contentId);
    }

    @Override
    public void addMomentsStatus(UserMomentsStatus momentsStatus) throws ConditionException {
        int res = momentsStatusMapper.insertSelective(momentsStatus);
        if (res == 0) {
            throw new ConditionException("添加动态状态信息失败");
        }
    }
}
